package com.itfreer.content.task;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.itfreer.content.R;
import com.itfreer.ui.activity.BaseActivity;
import com.itfreer.ui.activity.FormActivity;
import com.itfreer.ui.base.TextView;
import com.itfreer.ui.photoview.PhotoFragment;
import com.itfreer.ui.photoview.PhotoFragmentAdapter;
import com.itfreer.ui.photoview.PhotoInfo;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class TaskFormActivity extends FormActivity {

    private com.itfreer.ui.form.PhotoView gridView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_task_form);

        gridView = this.findViewById(R.id.task_gridview);
        gridView.setActivity(this);

        // 返回
        com.itfreer.ui.base.TextView back =(TextView)findViewById(R.id.taskFormBack);
        back.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                finish();
            }
        });

        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        TaskEntity taskEntity = (TaskEntity)bundle.getSerializable("entity");
        Map<String,Object> dataMap = object2Map(taskEntity);

        setDataBind(dataMap);
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        gridView.onActivityResult(requestCode, resultCode, data);
    }


    public Map<String,Object> object2Map(Object object){
        Map<String,Object> result=new HashMap<>();
        //获得类的的属性名 数组
        Field[]fields=object.getClass().getDeclaredFields();
        try {
            for (Field field : fields) {
                field.setAccessible(true);
                String name = new String(field.getName());
                result.put(name, field.get(object));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

}
